Ext.define("Mypocket.controller.SplashScreen", {
    extend: "Ext.app.Controller",
    requires: [""],
    config: {
        control: {           
            "#lookupBtn": {
                tap: "onLookupTap"
            },
            "#settingsBtn": {
                tap: "onSettingsTap"
            }
        }
    },
    init: function() {    	
        Ext.create("Mypocket.view.Main");
        Ext.getCmp("splashScreen").setActiveItem(Ext.getCmp("settingsForm"));
    },
    onSettingsTap: function() {
       var b = Ext.getCmp("splashScreen");
       
       
        b.getActiveItem() == Ext.getCmp("settingsForm") ? b.setActiveItem(Ext.getCmp("legislatorList")) : b.setActiveItem(Ext.getCmp("settingsForm"))
    },
     onLookupTap: function() {         
        this.loadLegislators();
        this.onSettingsTap()
    },
   
    loadLegislators: function() {   
      
        a = Ext.getStore("Legislators"),
        d = Ext.getCmp("splashToolbar");     
        
      var selectState= Ext.getCmp("selectState").getRecord().get('state');
      var selectAbbr=Ext.getCmp("selectState").getRecord().get('abbr');
    // 如果用户选择的市区跟当前市区不同则重新加载数据
      if(d.getData()!=selectAbbr){
       	d.setTitle(selectState);
      	d.setData(selectAbbr);
      	a.getProxy().setUrl("data/"+selectAbbr+".json"); 
      	a.load();
      }
      
    
       
      
    }
});